package com.vhuomai.order.service.impl;

import com.quanyue.auto.util.GlobalContext;
import com.vhuomai.order.entity.BaseCart;
import com.vhuomai.order.mapper.CartMapper;
import com.vhuomai.order.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    public void addCart(BaseCart cart, Integer userId) {
        cart.setId(null);
        cart.setUserId(userId);
        cart.setMerchantNo(GlobalContext.merchantNo());
        cart.setCreateTime(LocalDateTime.now());
        cart.setUpdateTime(LocalDateTime.now());
        cart.setDelFlag(false);
        cartMapper.insert(cart);
    }

    @Override
    public void deleteCart(Integer id) {
        cartMapper.deleteOne(id);
    }

    @Override
    public List <BaseCart> cartList(Integer userId) {
        return cartMapper.findByUserId(userId);
    }
}
